// components/goods/goodsRecommend/index.js
Component({

  externalClasses: ['custom-class'],

  /**
   * 组件的属性列表
   */
  properties: {
    title: String,
    titleBgColor:String,
    goods: Object,
    isShowCart: {
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    isChange: false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onNavToGoodsDetails (e) {
      console.log(e);
      const { platform_type, goods_id, mall_id } = e.currentTarget.dataset
      // 1:拼多多 2:淘宝 3:京东 4,自营
      switch (platform_type) {
        case 1:
        case 2:
        case 3:
          wx.navigateTo({
            url: `/pages/goods/detail/detail?id=${goods_id}&storeId=${mall_id}`
          });
          break;
        case 4:
          wx.navigateTo({
            url: `/pages/goods/mmallGoodsDetails/mmallGoodsDetails?id=${goods_id}&storeId=${mall_id}`
          });
          break;
        default:
          break;
      }
    },
    // 换一换
    onChange () {
      this.setData({
        isChange: true
      })
      let timer = setTimeout(() => {
        this.setData({
          isChange: false
        })
        clearTimeout(timer)
      }, 1000)
      this.triggerEvent('change')
    },

    onClick (event) {
      const { goodsid, goodsstatus } = event.currentTarget.dataset
      this.triggerEvent('click', {
        goodsId: goodsid,
        goodsStatus: goodsstatus
      }, {})
    },

    // 添加到购物车
    onAddCart (event) {
      const { goodsid, goodsstatus } = event.currentTarget.dataset
      this.triggerEvent('addCart', {
        goodsId: goodsid,
        goodsStatus: goodsstatus
      }, {})
    }
  }
})
